/*

 Copyright (c) 2008-2009 Fabrizio Pistonesi

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 */

#include "cubic.h"

Cubic::Cubic(IrrlichtDevice *device, s32 idn, stringc side[5]) : Node(device, idn, ENT_CUBIC)
  {
    for (int i = 0; i < 6; i++)
      {
        if (!Device->getFileSystem()->existFile(side[i].c_str()))
          {
            side[i] = "missing.png";
          }
        Texture[i] = Device->getVideoDriver()->getTexture(side[i].c_str());
        Sides[i] = side[i];
      }
    ThisNode = Device->getSceneManager()->addSkyBoxSceneNode(Texture[4],
        Texture[5], Texture[3], Texture[1], Texture[0], Texture[2], this->Root);
    ThisNode->setMaterialFlag(EMF_ANISOTROPIC_FILTER, true);
    ThisNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
    ThisNode->setIsDebugObject(true);
  }
//4 0
Cubic::~Cubic()
  {
  }

f32 Cubic::getRotation()
  {
    return this->ThisNode->getRotation().Y;
  }

//TODO: Rotation should be an UV offset.
void Cubic::setRotation(f32 degree)
  {
        ThisNode->setRotation(vector3d<f32> (0, degree, 0));
        Rotation = vector3d<f32> (0, degree, 0);
  }

void Cubic::reload(stringc side[5])
  {
    ThisNode->drop();
    for (int i = 0; i < 6; i++)
      {
        if (!Device->getFileSystem()->existFile(side[i].c_str()))
          {
            Device->getLogger()->log("Could not find the image: %s", side[i].c_str());
            side[i] = "missing.png";
          }
        Texture[i] = Device->getVideoDriver()->getTexture(side[i].c_str());
        Sides[i] = side[i];
      }
    Device->getSceneManager()->addSkyBoxSceneNode(Texture[0], Texture[1],
        Texture[2], Texture[3], Texture[4], Texture[5], this->Root);
  }
